<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.pengtu.security.SpringSecurityUtils"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="nav" content="0" />
<meta name="acc" content="1-1-0" />
<title>收文管理</title>
<style type="text/css">
.pop_box {
	background-color: #cccccc;
	display: none;
	padding: 5px;
	position: fixed;
	width: 100%;
	height: 100%;
	z-index: 9999;
}
</style>
<script type="text/javascript"
	src="<c:url value='/ext/ui/jquery-ui-1.8.12.custom.min.js'/>"></script>
<link href="${ctx}/styles/lightness/jquery-ui-1.8.12.custom.css"
	rel="stylesheet" />
<script type="text/javascript" charset="utf-8"
	src="<c:url value='/KindEditor/kindeditor.js'/>"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$("#title").focus();
						var $validate1 = $("#inputForm")
								.validate(
										{
											rules : {
												title : {
													required : true,
													remote : "${ctx}/admin/received!checkTitle.action?oldTitle="
															+ encodeURIComponent('${title}')
												},
												refeNum : {
													maxlength : 50,
													remote : "${ctx}/admin/received!checkRefeNum.action?oldRefeNum="
															+ encodeURIComponent('${refeNum}')
												},
												officeNum : {
													maxlength : 50
												},
												secret : "required",
												crash : "required"
											},
											messages : {
												title : {
													remote : "<font color='red'>收文标题已存在</font>"
												},
												refeNum : {
													remote : "<font color='red'>来文原号已存在</font>"
												}
											}
										});
						
						var $testDialog = $("#pop").dialog({
							title:"资料上传",
							autoOpen : false,
							modal : true
						});

						$("#check")
								.click(
										function() {
											var url = "${ctx}/account/json/userchooses.action";
											var obj = new Object();
											mm = window
													.showModalDialog(
															url,
															obj,
															'dialogHeight:500px;dialogWidth:780px;status:no;toolbar:no;resizable:no;menubar:no;location:no;scrollbars:no;dialogLeft:'
																	+ (screen.width / 2.0 - 150)
																	+ ',dialogTop:170')
											if (mm != null) {
												$("input[name='staffs']").val(
														mm);
											}
										});

						$("#process")
								.click(
										function() {
											if (isProcess()) {
												$("#inputForm")
														.attr("action",
																"${ctx}/admin/received!second.action");
												KE.sync("content");
												$("#inputForm").submit();
												if ($validate1.numberOfInvalids()) {
												} else {
													$testDialog.dialog('open');
												}
											}
										});
						
						$("#b_save").click(function() {
							KE.sync("content");
							$("#inputForm").submit();
							if ($validate1.numberOfInvalids()) {
							} else {
								$testDialog.dialog('open');
							}
						});
						
						$("#publishDate")
								.addClass("Wate")
								.bind(
										"click",
										function() {
											WdatePicker({
												skin : 'whyGreen',
												minDate : '#F{$dp.$D(\'publishDate\')}',
												dateFmt : 'yyyy-MM-dd'
											});
										});
					});

	KE.show({
		id : 'content',
		cssPath : './index.css',
		afterCreate : function(id) {
			KE.event.ctrl(document, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
			KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
				KE.sync(id);
				document.forms['inputForm'].submit();
			});
		}
	});

	var i = 1;
	function addFile(divName, fileName) {
		var dv = document.getElementById(divName);

		var file = document.createElement("input");
		file.type = "file";
		file.name = fileName;
		file.id = fileName + i;
		dv.appendChild(file);

		var btn = document.createElement("input");
		btn.type = "button";
		btn.id = btn.name = "btn" + i;
		btn.value = "删除";

		btn.onclick = function() {
			var b = document.getElementById(btn.id);
			dv.removeChild(b.nextSibling);
			dv.removeChild(b.previousSibling);
			dv.removeChild(b);
		}

		dv.appendChild(btn);
		dv.appendChild(document.createElement("BR"));

		i++;
	}
</script>
</head>
<body>
	<div class="pop_box" id="pop">
		<h4>正在上传资料，请耐心等待······</h4>
	</div>
	<br>
	<form action="${ctx}/admin/received!save.action" method="post"
		id="inputForm" class="yform" enctype="multipart/form-data">
		<div id="caption">
			<h6>${licenseplateNumber}收文登记</h6>
		</div>
		<input type="hidden" name="id" id="id" value="${id }" />
		<table class="noborder">
			<tr class="type-text">
				<td>文件标题</td>
				<td colspan="3"><input type="text" id="title" name="title"
					value="${title }" /></td>
			</tr>
			<tr class="type-text">
				<td>来文原号&nbsp;</td>
				<td><input type="text" id="refeNum" name="refeNum"
					value="${refeNum }" /></td>
				<td>收文编号&nbsp;</td>
				<td><input type="text" id="officeNum" name="officeNum"
					value="${officeNum }" /></td>
			</tr>
			<tr class="type-text">
				<td>紧急程度</td>
				<td><pt:code category="3053" name="crash" default="${crash }"></pt:code>
				</td>
				<td>密集程度</td>
				<td><pt:code category="3054" name="secret" default="${secret }"></pt:code>
				</td>
			</tr>
			<tr class="type-text">
				<td>公文来源</td>
				<td><input type="text" id="source" name="source"
					value="${source }" /></td>
				<td>发布日期&nbsp;</td>
				<td><input type="text" id="publishDate" name="publishDate"
					value="${publishDate }" /></td>
			</tr>
			<tr class="type-text">
				<td>内容简介</td>
				<td colspan="3"><textarea cols="112" rows="3" id="content"
						name="content">${content }</textarea></td>
			</tr>
			<tr class="type-text">
				<td>备注</td>
				<td colspan="3"><textarea cols="112" rows="3" id="remark"
						name="remark">${remark }</textarea></td>
			</tr>
			<tr class="type-text">
				<td><input type="button" value="添加上传"
					onclick="addFile('sources','upload')"></td>
				<td colspan="3" id="sources"></td>
			</tr>
		</table>
		<c:if test="${not empty attachmentSet }">
			<div>
				<div id="caption">
					<h6>${licenseplateNumber}已有附件</h6>
				</div>
				<table>
					<c:forEach items="${attachmentSet }" var="attachment"
						varStatus="state">
						<tr id="tr${state.index }">
							<td colspan="4"><a title="下载"
								href="${ctx}/servlet/annex?id=${attachment.id}">${attachment.upfileFileName}(${attachment.type})<fmt:formatDate
										value="${attachment.fileTime}" pattern="yyyy-MM-dd" />
							</a><span
								onclick="deleteAttachmentById('${attachment.id}','tr${state.index }')"
								class="delete" title="删除附件"></span></td>
						</tr>
					</c:forEach>
				</table>
			</div>
		</c:if>
		<div class="type-button">
			<input class="button" type="button" class="submit" value="暂存" id="b_save"/>&nbsp;
			<c:if test="${status == '01' || status == null }">
				<input class="submit" type="button" id="process" value="提交" />&nbsp;
			</c:if>
			<input class="reset" type="button" value="返回" class="rest"
				onclick="history.back()" />
		</div>
	</form>
</body>
</html>